const db = require('../config/database');

class SensorModel {
  // 获取实时数据
  static async getSensorData() {
    try {
      const [rows] = await db.execute(`
        SELECT 
          id,
          create_time as timestamp,
          name,
          value,
          box_id as boxId,
          status,
          conn_state as connState,
          update_time as connStateTimestamp
        FROM soil_sensor
        ORDER BY create_time DESC
      `);
      return rows;
    } catch (error) {
      console.error('Error fetching sensor data:', error);
      throw error;
    }
  }
}

module.exports = SensorModel; 